Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Syntax (programming languages)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Syntax_(programming_languages)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Syntax_programming_languages rootpage-Syntax_programming_languages skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Syntax (programming languages)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */


.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style>

<p>The <b>syntax</b> of <a href="Computer" title="Computer">computer</a> <a href="Source_code" title="Source code">source code</a> is the form that it has – specifically without concern for what it means (<a href="Semantics_(computer_science)" title="Semantics (computer science)">semantics</a>). Like a <a href="Natural_language" title="Natural language">natural language</a>, a <a href="Computer_language" title="Computer language">computer language</a> (i.e. a <a href="Programming_language" title="Programming language">programming language</a>) defines the <a href="Syntax" title="Syntax">syntax</a> that is valid for that language.<sup id="cite_ref-eopl_1-0" class="reference"><a href="#cite_note-eopl-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> A <a href="Syntax_error" title="Syntax error">syntax error</a> occurs when syntactically invalid source code is processed by an <a href="Programming_tool" title="Programming tool">tool</a> such as a <a href="Compiler" title="Compiler">compiler</a> or <a href="Interpreter_(computing)" title="Interpreter (computing)">interpreter</a>.
</p><p>The most commonly used languages are <a href="Text_file" title="Text file">text-based</a> with syntax based on sequences of <a href="Character_(computing)" title="Character (computing)">characters</a>. Alternatively, the syntax of a <a href="Visual_programming_language" title="Visual programming language">visual programming language</a> is based on relationships between graphical elements.
</p><p>When designing the syntax of a language, a designer might start by writing down examples of both legal and illegal <a href="String_(computer_science)" title="String (computer science)">strings</a>, before trying to figure out the general rules from these examples.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Levels_of_syntax">Levels of syntax</h2></div>
<p>Computer language syntax is generally distinguished into three levels:
</p>
<ul><li>Words – the lexical level, determining how characters form <a href="Token_(parser)" class="mw-redirect" title="Token (parser)">tokens</a>;</li>
<li>Phrases – the grammar level, narrowly speaking, determining how tokens form phrases;</li>
<li>Context – determining what objects or <a href="Variable_(computer_science)" title="Variable (computer science)">variables</a> names refer to, if <a href="Data_type" title="Data type">types</a> are valid, etc.</li></ul>
<p>Distinguishing in this way yields modularity, allowing each level to be described and processed separately and often independently.
</p><p>First, a <a href="Lexical_analysis" title="Lexical analysis">lexer</a> turns the linear sequence of characters into a <a href="Linearity" title="Linearity">linear</a> sequence of tokens; this is known as "<a href="Lexical_analysis" title="Lexical analysis">lexical analysis</a>" or "lexing".<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>
</p><p>Second, the parser turns the linear sequence of tokens into a <a href="Tree_structure" title="Tree structure">hierarchical syntax tree</a>; this is known as "<a href="Parsing" title="Parsing">parsing</a>" narrowly speaking. This ensures that the line of tokens conform to the formal grammars of the programming language. The parsing stage itself can be divided into two parts: the <a href="Parse_tree" title="Parse tree">parse tree</a>, or "concrete syntax tree", which is determined by the grammar, but is generally far too detailed for practical use, and the <a href="Abstract_syntax_tree" title="Abstract syntax tree">abstract syntax tree</a> (AST), which simplifies this into a usable form. The AST and contextual analysis steps can be considered a form of <a href="Compiler" title="Compiler">semantic analysis</a>, as they are adding meaning and interpretation to the syntax, or alternatively as informal, manual <a href="Implementation" title="Implementation">implementations</a> of syntactical rules that would be difficult or awkward to describe or implement formally.
</p><p>Thirdly, the contextual analysis resolves names and checks types. This modularity is sometimes possible, but in many real-world languages an earlier step depends on a later step – for example, <a href="The_lexer_hack" class="mw-redirect" title="The lexer hack">the lexer hack</a> in <a href="C_(programming_language)" title="C (programming language)">C</a> is because tokenization depends on context. Even in these cases, syntactical analysis is often seen as approximating this ideal model.
</p><p>The levels generally correspond to levels in the <a href="Chomsky_hierarchy" title="Chomsky hierarchy">Chomsky hierarchy</a>. Words are in a <a href="Regular_language" title="Regular language">regular language</a>, specified in the <a href="Lexical_grammar" title="Lexical grammar">lexical grammar</a>, which is a Type-3 grammar, generally given as <a href="Regular_expression" title="Regular expression">regular expressions</a>. Phrases are in a <a href="Context-free_language" title="Context-free language">context-free language</a> (CFL), generally a <a href="Deterministic_context-free_language" title="Deterministic context-free language">deterministic context-free language</a> (DCFL), specified in a <a href="Phrase_structure_grammar" title="Phrase structure grammar">phrase structure grammar</a>, which is a Type-2 grammar, generally given as <a href="Production_(computer_science)" title="Production (computer science)">production rules</a> in <a href="Backus%E2%80%93Naur_form" title="Backus–Naur form">Backus–Naur form</a> (BNF). Phrase grammars are often specified in much more constrained grammars than full <a href="Context-free_grammar" title="Context-free grammar">context-free grammars</a>, in order to make them easier to parse; while the <a href="LR_parser" title="LR parser">LR parser</a> can parse any DCFL in linear time, the simple <a href="LALR_parser" title="LALR parser">LALR parser</a> and even simpler <a href="LL_parser" title="LL parser">LL parser</a> are more efficient, but can only parse grammars whose production rules are constrained. In principle, contextual structure can be described by a <a href="Context-sensitive_grammar" title="Context-sensitive grammar">context-sensitive grammar</a>, and automatically analyzed by means such as <a href="Attribute_grammar" title="Attribute grammar">attribute grammars</a>, though, in general, this step is done manually, via <a href="Name_resolution_(programming_languages)" title="Name resolution (programming languages)">name resolution</a> rules and <a href="Type_checking" class="mw-redirect" title="Type checking">type checking</a>, and implemented via a <a href="Symbol_table" title="Symbol table">symbol table</a> which stores names and types for each scope.
</p><p>Tools have been written that automatically generate a lexer from a lexical <a href="Specification_(technical_standard)" title="Specification (technical standard)">specification</a> written in regular expressions and a parser from the phrase grammar written in BNF: this allows one to use <a href="Declarative_programming" title="Declarative programming">declarative programming</a>, rather than need to have procedural or functional programming. A notable example is the <a href="Lex_(software)" title="Lex (software)">lex</a>-<a href="Yacc" title="Yacc">yacc</a> pair. These automatically produce a <i>concrete</i> syntax tree; the parser writer must then manually write code describing how this is converted to an <i>abstract</i> syntax tree. Contextual analysis is also generally implemented manually. Despite the existence of these automatic tools, parsing is often implemented manually, for various reasons – perhaps the phrase structure is not context-free, or an alternative implementation improves performance or error-reporting, or allows the grammar to be changed more easily. Parsers are often written in functional languages, such as <a href="Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell</a>, or in scripting languages, such as <a href="Python_(programming_language)" title="Python (programming language)">Python</a> or <a href="Perl" title="Perl">Perl</a>, or in <a href="C_(programming_language)" title="C (programming language)">C</a> or <a href="C%2B%2B" title="C++">C++</a>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Syntax_definition">Syntax definition</h2></div>

<p>The syntax of textual programming languages is usually defined using a combination of <a href="Regular_expression" title="Regular expression">regular expressions</a> (for <a href="Lexical_analysis" title="Lexical analysis">lexical</a> structure) and <a href="Backus%E2%80%93Naur_form" title="Backus–Naur form">Backus–Naur form</a> (a <a href="Metalanguage" title="Metalanguage">metalanguage</a> for <a href="Context-free_grammar" title="Context-free grammar">grammatical</a> structure) to inductively specify <a href="Syntactic_category" title="Syntactic category">syntactic categories</a> (<a href="Terminal_and_nonterminal_symbols" title="Terminal and nonterminal symbols">nonterminal</a>) and <i><a href="Terminal_and_nonterminal_symbols" title="Terminal and nonterminal symbols">terminal</a></i> symbols.<sup id="cite_ref-:0_4-0" class="reference"><a href="#cite_note-:0-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> Syntactic categories are defined by rules called <i>productions</i>, which specify the values that belong to a particular syntactic category.<sup id="cite_ref-eopl_1-1" class="reference"><a href="#cite_note-eopl-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> Terminal symbols are the concrete characters or strings of characters (for example <a href="Keyword_(computer_programming)" class="mw-redirect" title="Keyword (computer programming)">keywords</a> such as <i>define</i>, <i>if</i>, <i>let</i>, or <i>void</i>) from which syntactically valid programs are constructed.
</p><p>Syntax can be divided into context-free syntax and context-sensitive syntax.<sup id="cite_ref-:0_4-1" class="reference"><a href="#cite_note-:0-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> Context-free syntax are rules directed by the metalanguage of the programming language. These would not be constrained by the context surrounding or referring that part of the syntax, whereas context-sensitive syntax would.
</p><p>A language can have different equivalent grammars, such as equivalent regular expressions (at the lexical levels), or different phrase rules which generate the same language. Using a broader category of grammars, such as LR grammars, can allow shorter or simpler grammars compared with more restricted categories, such as LL grammar, which may require longer grammars with more rules. Different but equivalent phrase grammars yield different parse trees, though the underlying language (set of valid documents) is the same.
</p>
<div class="mw-heading mw-heading3"><h3 id="Example:_Lisp_S-expressions">Example: Lisp S-expressions</h3></div>
<p>Below is a simple grammar, defined using the notation of regular expressions and <a href="Extended_Backus%E2%80%93Naur_form" title="Extended Backus–Naur form">Extended Backus–Naur form</a>. It describes the syntax of <a href="S-expression" title="S-expression">S-expressions</a>, a data syntax of the programming language <a href="Lisp_programming_language" class="mw-redirect" title="Lisp programming language">Lisp</a>, which defines productions for the syntactic categories <i>expression</i>, <i>atom</i>, <i>number</i>, <i>symbol</i>, and <i>list</i>:
</p>
<div class="mw-highlight mw-highlight-lang-ebnf mw-content-ltr" dir="ltr"><pre><span class="k">expression </span><span class="o">=</span> <span class="k">atom </span><span class="p">|</span> <span class="k">list</span>
<span class="k">atom </span><span class="err">=</span> <span class="k">number </span><span class="p">|</span> <span class="k">symbol </span>
<span class="k">number </span><span class="err">=</span> <span class="p">[</span><span class="err">+</span><span class="o">-</span><span class="p">]</span><span class="err">?</span><span class="p">[</span><span class="s1">'0'</span><span class="o">-</span><span class="s1">'9'</span><span class="p">]</span><span class="err">+</span>
<span class="k">symbol </span><span class="err">=</span> <span class="p">[</span><span class="s1">'A'</span><span class="o">-</span><span class="s1">'Z'</span><span class="p">][</span><span class="s1">'A'</span><span class="o">-</span><span class="s1">'Z''0'</span><span class="o">-</span><span class="s1">'9'</span><span class="p">].</span><span class="err">*</span>
<span class="k">list </span><span class="o">=</span> <span class="s1">'('</span><span class="p">,</span> <span class="k">expression</span><span class="err">*</span><span class="p">,</span> <span class="s1">')'</span>
</pre></div>
<p>This grammar specifies the following:
</p>
<ul><li>an <i>expression</i> is either an <i>atom</i> or a <i>list</i>;</li>
<li>an <i>atom</i> is either a <i>number</i> or a <i>symbol</i>;</li>
<li>a <i>number</i> is an unbroken sequence of one or more decimal digits, optionally preceded by a plus or minus sign;</li>
<li>a <i>symbol</i> is a letter followed by zero or more of any characters (excluding whitespace); and</li>
<li>a <i>list</i> is a matched pair of parentheses, with zero or more <i>expressions</i> inside it.</li></ul>
<p>Here the decimal digits, upper- and lower-case characters, and parentheses are terminal symbols.
</p><p>The following are examples of well-formed token sequences in this grammar: '<code>12345</code>', '<code>()</code>', '<code>(A B C232 (1))</code>'
</p>
<div class="mw-heading mw-heading3"><h3 id="Complex_grammars">Complex grammars</h3></div>
<p>The grammar needed to specify a programming language can be classified by its position in the <a href="Chomsky_hierarchy" title="Chomsky hierarchy">Chomsky hierarchy</a>. The phrase grammar of most programming languages can be specified using a Type-2 grammar, i.e., they are <a href="Context-free_grammar" title="Context-free grammar">context-free grammars</a>,<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup> though the overall syntax is context-sensitive (due to variable declarations and nested scopes), hence Type-1. However, there are exceptions, and for some languages the phrase grammar is Type-0 (Turing-complete).
</p><p>In some languages like Perl and Lisp the specification (or implementation) of the language allows constructs that execute during the parsing phase. Furthermore, these languages have constructs that allow the programmer to alter the behavior of the parser. This combination effectively blurs the distinction between parsing and execution, and makes syntax analysis an <a href="Undecidable_problem" title="Undecidable problem">undecidable problem</a> in these languages, meaning that the parsing phase may not finish. For example, in Perl it is possible to execute code during parsing using a <code>BEGIN</code> statement, and Perl function prototypes may alter the syntactic interpretation, and possibly even the syntactic validity of the remaining code.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> Colloquially this is referred to as "only Perl can parse Perl" (because code must be executed during parsing, and can modify the grammar), or more strongly "even Perl cannot parse Perl" (because it is undecidable). Similarly, Lisp <a href="Macro_instruction" class="mw-redirect" title="Macro instruction">macros</a> introduced by the <code>defmacro</code> syntax also execute during parsing, meaning that a Lisp compiler must have an entire Lisp run-time system present. In contrast, C macros are merely string replacements, and do not require code execution.<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Syntax_versus_semantics">Syntax versus semantics</h2></div>
<p>The syntax of a language describes the form of a valid program, but does not provide any information about the meaning of the program or the results of executing that program. The meaning given to a combination of symbols is handled by semantics (either <a href="Formal_semantics_of_programming_languages" class="mw-redirect" title="Formal semantics of programming languages">formal</a> or hard-coded in a <a href="Reference_implementation_(computing)" class="mw-redirect" title="Reference implementation (computing)">reference implementation</a>). Valid syntax must be established before semantics can make meaning out of it.<sup id="cite_ref-:0_4-2" class="reference"><a href="#cite_note-:0-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> Not all syntactically correct programs are semantically correct. Many syntactically correct programs are nonetheless ill-formed, per the language's rules; and may (depending on the language specification and the soundness of the implementation) result in an error on translation or execution. In some cases, such programs may exhibit <a href="Undefined_behavior" title="Undefined behavior">undefined behavior</a>. Even when a program is well-defined within a language, it may still have a meaning that is not intended by the person who wrote it.
</p><p>Using <a href="Natural_language" title="Natural language">natural language</a> as an example, it may not be possible to assign a meaning to a grammatically correct sentence or the sentence may be false:
</p>
<ul><li>"<a href="Colorless_green_ideas_sleep_furiously" title="Colorless green ideas sleep furiously">Colorless green ideas sleep furiously</a>." is grammatically well formed but has no generally accepted meaning.</li>
<li>"John is a married bachelor." is grammatically well formed but expresses a meaning that cannot be true.</li></ul>
<p>The following C language fragment is syntactically correct, but performs an operation that is not semantically defined (because <code class="mw-highlight mw-highlight-lang-c mw-content-ltr" style="" dir="ltr"><span class="n">p</span></code> is a <a href="Null_pointer" title="Null pointer">null pointer</a>, the operations <code class="mw-highlight mw-highlight-lang-c mw-content-ltr" style="" dir="ltr"><span class="n">p</span><span class="o">-&gt;</span><span class="n">real</span></code> and <code class="mw-highlight mw-highlight-lang-c mw-content-ltr" style="" dir="ltr"><span class="n">p</span><span class="o">-&gt;</span><span class="n">im</span></code> have no meaning):
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="w"> </span><span class="k">complex</span><span class="w"> </span><span class="o">*</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
<span class="w"> </span><span class="k">complex</span><span class="w"> </span><span class="n">abs_p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sqrt</span><span class="w"> </span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">real</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">p</span><span class="o">-&gt;</span><span class="n">real</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">p</span><span class="o">-&gt;</span><span class="n">im</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">p</span><span class="o">-&gt;</span><span class="n">im</span><span class="p">);</span>
</pre></div>
<p>As a simpler example,
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">x</span><span class="p">;</span>
<span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="p">);</span>
</pre></div>
<p>is syntactically valid, but not semantically defined, as it uses an <a href="Uninitialized_variable" title="Uninitialized variable">uninitialized variable</a>. Even though compilers for some programming languages (e.g., Java and C#) would detect uninitialized variable errors of this kind, they should be regarded as <a href="Programming_language#Semantics" title="Programming language">semantic</a> errors rather than syntax errors.<sup id="cite_ref-uninitialized_var_10-0" class="reference"><a href="#cite_note-uninitialized_var-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Comparison_of_programming_languages_(syntax)" title="Comparison of programming languages (syntax)">Comparison of programming languages (syntax)</a>
<ul><li><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */


.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}


/* end https://en.wikipedia.org/ */
</style><div class="hlist"><ul><li><a href="C_syntax" title="C syntax">C</a></li><li><a href="C%2B%2B_syntax" title="C++ syntax">C++</a></li><li><a href="Java_syntax" title="Java syntax">Java</a></li><li><a href="JavaScript_syntax" title="JavaScript syntax">JavaScript</a></li><li><a href="Haskell_syntax" class="mw-redirect" title="Haskell syntax">Haskell</a></li><li><a href="Lua_syntax" class="mw-redirect" title="Lua syntax">Lua</a></li><li><a href="Perl_language_structure#Basic_syntax" title="Perl language structure">Perl</a></li><li><a href="PHP_syntax_and_semantics" title="PHP syntax and semantics">PHP</a></li><li><a href="Prolog_syntax_and_semantics" title="Prolog syntax and semantics">Prolog</a></li><li><a href="Python_syntax_and_semantics" title="Python syntax and semantics">python</a></li></ul></div></li></ul></li>
<li><a href="Naming_convention_(programming)" title="Naming convention (programming)">Naming convention (programming)</a></li>
<li><a href="%22Hello%2C_World!%22_program" title="&quot;Hello, World!&quot; program">"Hello, World!" program</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-eopl-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-eopl_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-eopl_1-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFFriedmanMitchell_WandChristopher_T._Haynes1992" class="citation book cs1">Friedman, Daniel P.; Mitchell Wand; Christopher T. Haynes (1992). <i>Essentials of Programming Languages</i> (1st&nbsp;ed.). The MIT Press. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-262-06145-7</bdi>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite id="CITEREFSmith1999" class="citation book cs1">Smith, Dennis (1999). <i>Designing Maintainable Software</i>. Springer Science &amp; Business Media.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite id="CITEREFPaiAithal2020" class="citation journal cs1">Pai, Vaikunta; Aithal, P.S. (December 31, 2020). <a rel="nofollow" class="external text" href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3770588">"A Systematic Literature Review of Lexical Analyzer Implementation Techniques in Compiler Design"</a>. <i>International Journal of Applied Engineering and Management Letters</i>. <b>4</b> (2): <span class="nowrap">285–</span>301. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.47992%2FIJAEML.2581.7000.0087">10.47992/IJAEML.2581.7000.0087</a></span>. <a href="ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a>&nbsp;<a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/2581-7000">2581-7000</a>. <a href="SSRN_(identifier)" class="mw-redirect" title="SSRN (identifier)">SSRN</a>&nbsp;<a rel="nofollow" class="external text" href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3770588">3770588</a>.</cite></span>
</li>
<li id="cite_note-:0-4"><span class="mw-cite-backlink">^ <a href="#cite_ref-:0_4-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-:0_4-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-:0_4-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFSlonegggerKurtz1995" class="citation book cs1">Sloneggger, Kenneth; Kurtz, Barry (1995). <i>Formal Syntax and Semantics of Programming Languages</i>. <a href="Addison-Wesley_Publishing_Company" class="mw-redirect" title="Addison-Wesley Publishing Company">Addison-Wesley Publishing Company</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-201-65697-3</bdi>.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite id="CITEREFMichael_Sipser1997" class="citation book cs1"><a href="Michael_Sipser" title="Michael Sipser">Michael Sipser</a> (1997). "2.2 Pushdown Automata". <a rel="nofollow" class="external text" href="https://archive.org/details/introductiontoth00sips"><i>Introduction to the Theory of Computation</i></a>. PWS Publishing. pp.&nbsp;<span class="nowrap">101–</span>114. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-534-94728-X</bdi>.</cite></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://lambda-the-ultimate.org/node/3564#comment-50578">LtU comment clarifying that the undecidable problem is membership in the class of Perl programs</a></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.modernperlbooks.com/mt/2009/08/on-parsing-perl-5.html">chromatic's example of Perl code that gives a syntax error depending on the value of random variable</a></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20130806054148/http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html">"An Introduction to Common Lisp Macros"</a>. Apl.jhu.edu. 1996-02-08. Archived from <a rel="nofollow" class="external text" href="http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html">the original</a> on 2013-08-06<span class="reference-accessdate">. Retrieved <span class="nowrap">2013-08-17</span></span>.</cite></span>
</li>
<li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://cl-cookbook.sourceforge.net/macros.html">"The Common Lisp Cookbook - Macros and Backquote"</a>. Cl-cookbook.sourceforge.net. 2007-01-16<span class="reference-accessdate">. Retrieved <span class="nowrap">2013-08-17</span></span>.</cite></span>
</li>
<li id="cite_note-uninitialized_var-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-uninitialized_var_10-0">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.dummies.com/how-to/content/semantic-errors-in-java.html">Semantic Errors in Java</a></span>
</li>
<li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://stackoverflow.com/questions/8803718/issue-of-syntax-or-semantics/8803765#8803765">Issue of syntax or semantics?</a></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li>Various syntactic constructs used in <a rel="nofollow" class="external text" href="https://rigaux.org/language-study/syntax-across-languages/">computer programming languages</a></li>
<li>Python error “ImportError: No module named” Why? How? Command-Line? <a rel="nofollow" class="external text" href="https://usingpython.shodkk.com/python-error-importerror-no-module-named-why-how-command-line-solved2021/">[Solved2021]</a>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20211009062019/https://usingpython.shodkk.com/python-error-importerror-no-module-named-why-how-command-line-solved2021/">Archived</a> 2021-10-09 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-08-03" href="https://en.wikipedia.org/wiki/?title=Syntax_(programming_languages)&amp;oldid=1303976535">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>